package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.DishMapper;
import com.sky.mapper.WxDishMapper;
import com.sky.service.WxDishService;
import com.sky.vo.DishVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WxDishServiceImpl implements WxDishService {
    @Autowired
    WxDishMapper wxDishMapper;
    @Autowired
    DishMapper dishMapper;
    @Autowired
    DishFlavorMapper dishFlavorMapper;
    @Override
    public List<DishVO> queryListByCategoryDish(Dish dish) {
        List<Dish> dishList = dishMapper.list(dish);
        ArrayList<DishVO> dishVoList = new ArrayList<>();
        dishList.forEach(e ->{
            DishVO dishVO = new DishVO();
            // 将e拷贝到dishVo
            BeanUtils.copyProperties(e,dishVO);
            // 查询对应的口味
           List<DishFlavor> flavor =  dishFlavorMapper.queryDishFlavor(dishVO.getId());
           // 添加对应的口味
            dishVO.setFlavors(flavor);
            // 添加进数组
            dishVoList.add(dishVO);
        });
        return dishVoList;
    }
}
